/**
 * Created by Richard Radlherr.
 * Date: 16.06.2006 10:06
 */
using System;
using System.Collections.Generic;
using TagTool.Core;
using TagTool.GraphicTypes;

namespace TagTool.Nodes.Drawing
{
	
	public class VertexRecorder : BaseNode
	{
		
		private InputSlot location;
		private InputSlot color;
		private InputSlot width;
		
		private InputSlot reset;
		
		private OutputSlot points;
		private OutputSlot colors;
		private OutputSlot widths;
		
		private OutputSlot combined;
		
		private OutputSlot count;
		private InputSlot startStop;

		public VertexRecorder() : base()
		{
			Name = "Vertex Recorder";
			location = new InputSlot(this, "Location", new PointD());
			location.ParseCallback = ParseHelper.ParseVector;
			
			color = new InputSlot(this, "Color", new Color());
			color.ParseCallback = ParseHelper.ParseColor;
			
			width = new InputSlot(this, "Width", 0.0);
			width.ParseCallback = ParseHelper.ParseDouble;
			
			reset = new InputSlot(this, "Reset", false);
			
			startStop = new InputSlot(this, "Start/Stop", false);
			
			points = new OutputSlot(this, "Points", typeof(List<PointD>));
			points.Value = new List<PointD>();
			
			colors = new OutputSlot(this, "Colors", typeof(List<Color>));
			colors.Value = new List<Color>();
			
			widths = new OutputSlot(this, "Widths", typeof(List<double>));
			widths.Value = new List<double>();
			
			combined = new OutputSlot(this, "Combined", typeof(List<ColoredPoint>));
			combined.Value = new List<ColoredPoint>();
			
			count = new OutputSlot(this, "Count", typeof(double));
			count.Value = 0.0;
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot Location
		{
			get { return location; }
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot Color
		{
			get { return color; }
		}
		
		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot Width
		{
			get { return width; }
		}
		
		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot Reset
		{
			get { return reset; }
		}
		
		[NodeAttribute(SlotType.Output, Show = true, ValueTypeName = "List<PointD>")]
		public OutputSlot Points
		{
			get { return points; }
		}
		
		[NodeAttribute(SlotType.Output, Show = true, ValueTypeName = "List<Color>")]
		public OutputSlot Colors
		{
			get { return colors; }
		}
		
		[NodeAttribute(SlotType.Output, Show = true, ValueTypeName = "List<double>")]
		public OutputSlot Widths
		{
			get { return widths; }
		}
		
		[NodeAttribute(SlotType.Output, Show = true, ValueTypeName = "List<ColoredPoint>")]
		public OutputSlot Combined
		{
			get { return combined; }
		}
		
		[NodeAttribute(SlotType.Output, Show = true)]
		public OutputSlot Count
		{
			get { return count; }
		}
		
		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot StartStop
		{
			get { return startStop; }
		}

		public override void Update(Object sender)
		{
			if ((bool)reset.Value)
			{
				((List<PointD>)points.Value).Clear();
				((List<Color>)colors.Value).Clear();
				((List<double>)widths.Value).Clear();
				combined.Value = new List<ColoredPoint>();
				count.Value = (double)((List<PointD>)points.Value).Count;
				
				CastTrigger();
			}
			else
			{
				if ((bool)startStop.Value)
				{
					((List<Color>)colors.Value).Add((Color)color.Value);
					((List<PointD>)points.Value).Add((PointD)location.Value);
					((List<double>)widths.Value).Add((double)width.Value);
					((List<ColoredPoint>)combined.Value).Add(new ColoredPoint((PointD)location.Value, (Color)color.Value, (double)width.Value));
					count.Value = (double)((List<PointD>)points.Value).Count;
					
					CastTrigger();
				}
			}
			
			
		}

	}
}
